<template>
	<view class='warp'>
		<view class="name" style="width: 100%;padding-left: 30rpx;">门店名称:{{store.nickname || '无'}}</view>
		<view style="width: 90%;margin-left: 50%;transform: translateX(-50%);">

			<view class="detail-desc" v-for="equipment in list" :key="equipment.id">
				<image :src="equipment.image" style="width: 150rpx;height: 150rpx;margin: 20rpx;"></image>
				<view style="width: calc(100% - 150rpx)">
					<view class="word-omit" style="color: #333333;">{{ equipment.store_name }}</view>
					<view :style="{color:'#5490FE',fontSize:'20rpx'}">品牌型号：{{ equipment.cate1  ||  equipment.cate_name1 ||   equipment.cate_name}}</view>
					<view style="font-size: 26rpx;" :class="[userInfo.is_worker == 2? 'word-omit' : 'text-omit']">
						核心零配件：{{ equipment.store_info }}</view>
					<view class="detail-num">
						<text class="c66">添加数量</text>
						<wm-numberBox model="0" :value="equipment.num || 0" :ID="equipment.id" @change="addShopCart">
						</wm-numberBox>
					</view>

				</view>
			</view>
		</view>

		<view class="footer flex">
			<view class="btn" @click="addsb">添加设备</view>
			<view class="btn1 btn" @click="confrim">确认提交</view>
		</view>
	</view>
</template>

<script>
	import wmNumberBox from "@/components/wm-numberBox/wm-number-box.vue"
	import {
		deviceAdd
	} from '../../../api/api.js'
	export default {
		components: {
			wmNumberBox,
		},
		data() {
			return {
				list: [],
				store: {}
			}

		},
		onLoad() {
			this.store = uni.getStorageSync('store')
			this.oldshop = uni.getStorageSync('oldshop')
			this.newshop = uni.getStorageSync('newshop')
			// if (!this.oldshop) {
			// 	return this.list = this.list.concat(this.newshop)
			// }
			// if (!this.newshop) {
			// 	return this.list = this.list.concat(this.oldshop)
			// }
			this.list = this.list.concat(this.oldshop, this.newshop)
		},
		methods: {
			addsb() {
				uni.navigateTo({
					url: "/pages/sf/savesb/index"
				})
			},
			addShopCart(e) {
				console.log(a,b)
				this.newshop.forEach(item=>{
					if(e.id == item.id){
						item.num = e.value
					}
				})
				this.oldshop.forEach(item=>{
					if(e.id == item.id){
					item.num = e.value
					}
				})
				
			},
			// 提交
			confrim() {
				this.newshop.forEach(item=>{
					item.id = 0
				})
					let oldshop = []
					let news ={}
				this.oldshop.forEach(item=>{
					if(item.goods_id){
						oldshop.push({'id':item.id,'goods_id':item.goods_id,'num':item.num})
					}
					if(item.flag){
						oldshop.push({'id':0,'goods_id':item.id,'num':item.num})
					}
				})
			// console.log(oldshop)
				let data = {
						user_id: this.store.uid, // "90300054",
						goods: JSON.stringify(oldshop) ,
						"new_goods":JSON.stringify(this.newshop) 
					};
				// return;
					deviceAdd(data).then(res => {
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
						if(res.status == 200)
						uni.redirectTo({
							url:'/pages/sf/sbgl/sbgl'
						})
					})
			},

		}
	}
</script>

<style scoped lang='less'>
	.detail-desc {
		display: flex;
		margin-top: 30rpx;
		background: #F6F9FF;
		width: 100%;
		overflow-y: auto;
	}

	.detail-list::-webkit-scrollbar {
		display: none;
	}

	.detail-num {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.word-omit {
		/*word-break:break-all;*/
		white-space: nowrap;
		color: #666666;
		/*强制在一行显示*/
		text-overflow: ellipsis;
		/*设置超出内容显示...*/
		overflow: hidden;
		/*一定不能少 超出的内容进行隐藏*/
	}

	.name {
		width: 100%;
		background-color: #F6F9FF;
		font-size: 32rpx;
		color: #666666;

	}

	.text-omit {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		color: #999999;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}


	.footer {
		width: 100%;
		position: fixed;
		bottom: 100rpx;
		font-size: 26rpx;
		color: #FFFFFF;
		/* padding-left:50rpx; */

		.btn {
			height: 60rpx;
			width: 40%;
			margin: 0 5%;
			border-radius: 30rpx;
			background-color: #007AFF;
			text-align: center;
			line-height: 60rpx;
		}

		.btn1 {
			margin: 0 5%;
			background-color: #FECB54;
		}
	}
</style>
